<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport"
        content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
	<link rel="stylesheet" type="text/css" href="../../css/api.css" />
	<link rel="stylesheet" type="text/css" href="../../css/common.css" />
	<link rel="stylesheet" type="text/css" href="../../css/aui.css" />
  <link rel="stylesheet" type="text/css" href="../../css/aui-pull-refresh.css" />
  <title>学术</title>
  <style>
		html, body {width: 100%;min-height: 100%;background: #f0f0f0;}
    .h20 {height: 0.5rem;background: #f0f0f0;}

    .lwTab_outer {
      width: 100%;
      overflow-x: auto;
    }
    .lwTab {
      display: block;
      width: auto;
    }
    .lwTab::before,
    .lwTab::after {
      content: '';
      display: block;
      height: 0;
      clear: both;
    }
    .lwTab .aui-tab-item {
      border: none;
      position: relative;
      float: left;
      width: auto;
      padding: 0 0.5rem;
      white-space:nowrap;
    }
    .lwTab .aui-tab-item.aui-active {
      color: #2997e4;
    }
    .xs_img img {
      width: 0.6rem;
      display: inline-block;
      vertical-align: middle;
    }
    .lwContent {
      /*padding-top: calc(0.5rem + 44px);*/
      padding-bottom: 2.6rem;
      /*min-height: calc(100vh - 40px - 2.6rem);*/
    }
    #app {
      padding-top: calc(0.5rem + 44px);
    }
    .lt_btn {
      position: fixed;
      left: 0;
      bottom: 0;
      width: 100%;
    }
    .lt_btn a {
      display: block;
      width: 100%;
      text-align: center;
      padding: 10px 0;
      color: #fff;
      font-size: 0.8rem;
      background: #2997e4;
      font-weight: bold;
    }
    .lwTab_outer {
      position: fixed;
      /*width: 100%;*/
      top:0;
      z-index: 99;
      overflow-x: auto;
    }
	</style>
</head>
<body>
  <div id="app" v-cloak>
<div class="lwTab_outer">
  <div class="aui-tab lwTab" id="lwTab">
    <div class="aui-tab-item" :class="{'aui-active': index == 0}" v-for="(item, index) in type" :key="index" @click="typeId = item.id">{{item.papertype}}</div>
  </div>
</div>

<section class="aui-refresh-content">
<div class="aui-content lwContent">
  <ul class="aui-list aui-media-list">
    <li class="aui-list-item" @click="openDetail('lw', '详情', item.id)" v-for="item in newsList">
      <div class="aui-media-list-item-inner">
        <div class="aui-list-item-inner">
          <div class="aui-list-item-text">
            <div class="aui-list-item-title">{{item.title}}</div>
          </div>
          <div class="aui-list-item-text aui-ellipsis-2">
            <div class="xs_img">
              <img src="../../image/eye@3x.png" alt=""> {{item.click_count}}
            </div>
          </div>
        </div>
      </div>
    </li>
  </ul>
</div>
</section>

<div class="lt_btn">
  <a href="javascript:;" @click="fblw(typeId)">发布论文</a>
</div>
</div>
</body>
<script src="../../script/aui-tab.js"></script>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/vue.min.js"></script>
<script type="text/javascript" src="../../script/utils.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>
<script type="text/javascript" src="../../script/aui-scroll.js"></script>
<script src="../../script/aui-pull-refresh.js"></script>
<script>
apiready = function() {

  var app = new Vue({
    el: '#app',
    data: {
      type: [],
      typeId: 0,
      newsList: [],
		  page: 1,
      totalpage: 1
    },
    created: function() {
      var $_this = this;
      api.ajax({
        url: window.Url.getPaperType,
        timeout: 300,
      }, function(ret, err) {
          if (ret) {
              // api.alert({ msg: JSON.stringify(ret) });
                $_this.type = ret.data
                $_this.typeId = ret.data[0].id
                $_this.$nextTick(function () {
                  var lwTab = document.querySelector('#lwTab')
                  var lwTabI = document.querySelectorAll('.aui-tab-item')
                  var lwTabW = 0
                  for (var i = 0; i < lwTabI.length; i++) {
                    lwTabW += lwTabI[i].offsetWidth
                  }
                  lwTab.style.width = lwTabW + 'px'
                  var tab = new auiTab({
                    element:document.getElementById("lwTab"),
                    index:1,
                    repeatClick:false
                  },function(ret){
                  // $_this.getList()
                  });
                })
          } else {
              api.alert({ msg: JSON.stringify(err) });
          }
      })


      var scroll = new auiScroll({
            listen:true, //是否监听滚动高度，开启后将实时返回滚动高度
            distance:40 //判断到达底部的距离，isToBottom为true
        },function(ret){
           if (ret.isToBottom) {
             $_this.page ++
             if ($_this.page > $_this.totalpage) {
               $_this.page = $_this.totalpage
               return
             }
             api.ajax({
               url: window.Url.getPaperList + $_this.typeId + '/' + $_this.page,
     					timeout: 300,
     				}, function(ret, err) {
     				    if (ret) {
     				       //  api.alert({ msg: JSON.stringify(ret) });
     								$_this.newsList = $_this.newsList.concat(ret.data.newsList)

     				    } else {
     				        api.alert({ msg: JSON.stringify(err) });
     				    }
     				})
           }

        });


    },
    methods: {
      getList: function () {
        var $_this = this;
        api.ajax({
          url: window.Url.getPaperList + $_this.typeId + '/' + $_this.page,
          timeout: 300,
        }, function(ret, err) {
            if (ret) {
                // api.alert({ msg: JSON.stringify(ret) });
                if (ret.code == 1) {
                  return
                }
  								$_this.totalpage = ret.data.totalpage
                  $_this.newsList = ret.data.newsList
            } else {
                api.alert({ msg: JSON.stringify(err) });
            }
        })
      },
      openDetail: function (type, title, id) {
        api.openWin({
          name: 'index_detail_' + type,
          pageParam: {
            name: 'index_detail_' + type,
            title: title,
            id: id
          },
          url: './index_detail_lw.html',
          delay: 200,
          bounces: false
        });
      },
        fblw:function (typeId) {
          api.openWin({
            name: 'index_sj_fblw',
            pageParam: {
              name: 'index_sj_fblw',
              typeId: typeId
            },
            url: './index_sj_fblw.html',
            delay: 200,
            bounces: false
          });
        }
    },
    watch: {
      typeId: function () {
        this.page = 1
        this.getList()
      }
    },
    mounted: function () {
      var $_this = this;

              var pullRefresh = new auiPullToRefresh({
                  container: document.querySelector('.aui-refresh-content'),
                  triggerDistance: 100
              },function(ret){
                  if(ret.status=="success"){
                    $_this.page = 1
                    api.ajax({
                      url: window.Url.getPaperList + $_this.typeId + '/' + $_this.page,
                      timeout: 300,
                    }, function(ret, err) {
                        if (ret) {
                            // api.alert({ msg: JSON.stringify(ret) });
                            setTimeout(function() {
                                if (ret.code == 1) {
                                  pullRefresh.cancelLoading(); //刷新成功后调用此方法隐藏
                                  return
                                }
                    							$_this.totalpage = ret.data.totalpage
                                  $_this.newsList = ret.data.newsList
                                  pullRefresh.cancelLoading(); //刷新成功后调用此方法隐藏
                            },500)
                        } else {
                            api.alert({ msg: JSON.stringify(err) });
                        }
                    })
                  }
              })
    }
  })
}




</script>
</html>
